package com.lanswon.icc.common.core.util;

import lombok.experimental.UtilityClass;

import java.util.UUID;

/**
 * @Description
 * @Author zsw
 * @Date 2019/11/11 16:30
 * @Version V1.0
 **/
@UtilityClass
public class CommonUtils {

    public String getUUID(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    /**
     * 驼峰转下划线
     * @param str
     * @return
     */
    public static String camelToUnderline(String str) {
        if (str == null || str.trim().isEmpty()){
            return "";
        }
        int len = str.length();
        StringBuilder sb = new StringBuilder(len);
        sb.append(str.substring(0, 1).toLowerCase());
        for (int i = 1; i < len; i++) {
            char c = str.charAt(i);
            if (Character.isUpperCase(c)) {
                sb.append("_");
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }


    public static void main(String[] args) {


        System.out.println(camelToUnderline("username"));
    }
}